<?php
/**
 * @Author: lianlianzan(13040@qq.com)
 * @Date:   2018-08-18 16:40:16
 * @Last Modified by:   lianlianzan(13040@qq.com)
 * @Last Modified time: 2020-12-03 00:32:30
 */

namespace app\admin\controller;
use app\common\controller\Backend;

class Aboutus extends Backend {

	private $config_space = 'explain';

	function initialize() {
		parent::initialize();
		$this->saveAndGetConfigIdentify('', '系统配置', '', 'aboutus');

		$this->explainDao = model('common/Explain');
	}

	public function index() {
		$info = $this->explainDao->getConfigsBySpace($this->config_space);
		//print_r($info);
		$this->assign('info', $info);

		return $this->fetch();
	}

	public function doSet() {
		$data = input('post.data/a', '', '');

		$info = $this->explainDao->getConfigsBySpace($this->config_space);

		//处理编辑器内容
		$data['aboutus'] = ueditorContent($data['aboutus']);
		
		foreach ($data as $key => $value) {
			$checkInfo = $this->explainDao->getConfigByNameAndSpace($key, $this->config_space);
			$sqlData = [
				'config_value'	=> $value,
			];
			//print_r($checkInfo);
			if ($checkInfo) {
				$this->explainDao->updateConfigByNameAndSpace($key, $this->config_space, $sqlData);
			} else {
				$sqlData['config_space'] = $this->config_space;
				$sqlData['config_name'] = $key;
				$sqlData['description'] = '';
				$this->explainDao->insert($sqlData);
			}
		}
		
		$sys_identify = 'explain';
		cache($sys_identify, NULL); //删除缓存数据

		$this->success('保存成功');
	}

}